package com.ncmmall.domain.business.merchant.freight;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ncmmall.domain.security.user.WebUser;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * 商家运费
 *
 * @author likaikai
 * @date 2019-07-08 11:36
 */
@Entity
@Table(name = "mall_merchant_freight")
@Access(AccessType.FIELD)
public class MerchantFreight {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    /**
     * 城市
     */
    private String city;

    /**
     * 关联商家
     */
    @OneToOne
    private WebUser merchant;

    /**
     * 计价方式
     * 1、按重量
     * 2、按件数
     */
    private int type;

    /**
     * 首重（单位：g）
     */
    private int firstWeight;

    /**
     * 首费（元）
     */
    private double firstWeightAmount;

    /**
     * 续重（单位：g）
     */
    private int otherWeight;

    /**
     * 续费（元）
     */
    private double otherWeightAmount;

    /**
     * 首件（单位：件）
     */
    private int firstPiece;

    /**
     * 首费（元）
     */
    private double firstPieceAmount;

    /**
     * 续件（单位：件）
     */
    private int otherPiece;

    /**
     * 续费（元）
     */
    private double otherPieceAmount;

    /**
     * 运费自身关联
     */
    @ManyToOne
    @JoinColumn(name = "parentId")
    @NotFound(action = NotFoundAction.IGNORE)
    private MerchantFreight parent;

    /**
     * 运费自身关联
     */
    @JsonBackReference
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "parentId", nullable = true)
    private List<MerchantFreight> merchantFreights;

    /**
     * 所属运费模板
     */
    @ManyToOne
    @JoinColumn(name = "templateId")
    @NotFound(action = NotFoundAction.IGNORE)
    private MerchantFreightTemplate template;

    /**
     * 运费列表城市
     */
    @Transient
    private String citys;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public WebUser getMerchant() {
        return merchant;
    }

    public void setMerchant(WebUser merchant) {
        this.merchant = merchant;
    }

    public int getFirstWeight() {
        return firstWeight;
    }

    public void setFirstWeight(int firstWeight) {
        this.firstWeight = firstWeight;
    }

    public double getFirstWeightAmount() {
        return firstWeightAmount;
    }

    public void setFirstWeightAmount(double firstWeightAmount) {
        this.firstWeightAmount = firstWeightAmount;
    }

    public int getOtherWeight() {
        return otherWeight;
    }

    public void setOtherWeight(int otherWeight) {
        this.otherWeight = otherWeight;
    }

    public double getOtherWeightAmount() {
        return otherWeightAmount;
    }

    public void setOtherWeightAmount(double otherWeightAmount) {
        this.otherWeightAmount = otherWeightAmount;
    }

    public int getFirstPiece() {
        return firstPiece;
    }

    public void setFirstPiece(int firstPiece) {
        this.firstPiece = firstPiece;
    }

    public double getFirstPieceAmount() {
        return firstPieceAmount;
    }

    public void setFirstPieceAmount(double firstPieceAmount) {
        this.firstPieceAmount = firstPieceAmount;
    }

    public int getOtherPiece() {
        return otherPiece;
    }

    public void setOtherPiece(int otherPiece) {
        this.otherPiece = otherPiece;
    }

    public double getOtherPieceAmount() {
        return otherPieceAmount;
    }

    public void setOtherPieceAmount(double otherPieceAmount) {
        this.otherPieceAmount = otherPieceAmount;
    }

    public MerchantFreight getParent() {
        return parent;
    }

    public void setParent(MerchantFreight parent) {
        this.parent = parent;
    }

    public List<MerchantFreight> getMerchantFreights() {
        return merchantFreights;
    }

    public void setMerchantFreights(List<MerchantFreight> merchantFreights) {
        this.merchantFreights = merchantFreights;
    }

    public MerchantFreightTemplate getTemplate() {
        return template;
    }

    public void setTemplate(MerchantFreightTemplate template) {
        this.template = template;
    }

    public String getCitys() {
        return citys;
    }

    public void setCitys(String citys) {
        this.citys = citys;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
}
